// pages/menu/menu.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: true,
    selectedAddress: wx.getStorageSync('selectedAddress')||{},
    selectIndex:1,
    scrollTop:0,
    menus:[
      {
        sort:1,
        name:"奈雪早餐",
        id:6905,
        goods_list:[
          {
            content:"购买三明治,享早餐指定饮品半价",
            id:65825,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/19/fda6dd99c83af02353.jpg?imageView2/2/w/400/h/400",
            name:"奈雪早餐",
            price:20,
            property:[]
          },
          {
            content:"购买三明治,享早餐指定饮品半价",
            id:658268,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/19/fda6dd99c83af02353.jpg?imageView2/2/w/400/h/400",
            name:"奈雪早餐2",
            price:21,
            property:[]
          },          {
            content:"购买三明治,享早餐指定饮品半价",
            id:658267,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/19/fda6dd99c83af02353.jpg?imageView2/2/w/400/h/400",
            name:"奈雪早餐2",
            price:21,
            property:[]
          },          {
            content:"购买三明治,享早餐指定饮品半价",
            id:658266,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/19/fda6dd99c83af02353.jpg?imageView2/2/w/400/h/400",
            name:"奈雪早餐2",
            price:21,
            property:[]
          },          {
            content:"购买三明治,享早餐指定饮品半价",
            id:658265,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/19/fda6dd99c83af02353.jpg?imageView2/2/w/400/h/400",
            name:"奈雪早餐2",
            price:21,
            property:[]
          },          {
            content:"购买三明治,享早餐指定饮品半价",
            id:658264,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/19/fda6dd99c83af02353.jpg?imageView2/2/w/400/h/400",
            name:"奈雪早餐2",
            price:21,
            property:[]
          },          {
            content:"购买三明治,享早餐指定饮品半价",
            id:658263,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/19/fda6dd99c83af02353.jpg?imageView2/2/w/400/h/400",
            name:"奈雪早餐2",
            price:21,
            property:[]
          },          {
            content:"购买三明治,享早餐指定饮品半价",
            id:658262,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/19/fda6dd99c83af02353.jpg?imageView2/2/w/400/h/400",
            name:"奈雪早餐2",
            price:21,
            property:[]
          },          {
            content:"购买三明治,享早餐指定饮品半价",
            id:658261,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/19/fda6dd99c83af02353.jpg?imageView2/2/w/400/h/400",
            name:"奈雪早餐2",
            price:21,
            property:[]
          },
          {
            content:"购买三明治,享早餐指定饮品半价",
            id:65827,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/19/fda6dd99c83af02353.jpg?imageView2/2/w/400/h/400",
            name:"奈雪早餐3",
            price:22,
            property:[]
          }
        ]
      },
      {
        sort:2,
        name:"新品推荐",
        id:6208,
        goods_list:[
          {
            content:"酥软口感,进口奶油搭配特制巧克力内馅",
            id:223306,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/29/4a62ee45dd527609ed.jpg?imageView2/2/w/400/h/400",
            name:"脏脏王",
            price:18,
            property:[]
          },          {
            content:"酥软口感,进口奶油搭配特制巧克力内馅",
            id:245162233,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/29/4a62ee45dd527609ed.jpg?imageView2/2/w/400/h/400",
            name:"脏脏王",
            price:18,
            property:[]
          },          {
            content:"酥软口感,进口奶油搭配特制巧克力内馅",
            id:223,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/29/4a62ee45dd527609ed.jpg?imageView2/2/w/400/h/400",
            name:"脏脏王",
            price:18,
            property:[]
          },          {
            content:"酥软口感,进口奶油搭配特制巧克力内馅",
            id:2233,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/29/4a62ee45dd527609ed.jpg?imageView2/2/w/400/h/400",
            name:"脏脏王",
            price:18,
            property:[]
          },          {
            content:"酥软口感,进口奶油搭配特制巧克力内馅",
            id:22333,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/29/4a62ee45dd527609ed.jpg?imageView2/2/w/400/h/400",
            name:"脏脏王",
            price:18,
            property:[]
          },
          {
            content:"精选北川半兵卫抹茶粉和秘制红豆泥",
            id:24517,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/29/99daa7b20061efab10.jpg?imageView2/2/w/400/h/400",
            name:"抹茶王",
            price:18,
            property:[]
          },
          {
            content:"饱满大颗的新鲜杨梅,满杯手工去核,搭配茉莉初雪茶底,清爽多汁",
            id:68339,
            images:"https://img-shop.qmimg.cn/s23107/2020/04/26/559a075d81060b23c7.jpg?imageView2/2/w/400/h/400",
            name:"霸气杨梅",
            price:30,
            property:[]
          }
        ]
      }
    ],
    ads: [{
        image: 'https://img-shop.qmimg.cn/s23107/2020/04/27/4ebdb582a5185358c4.jpg?imageView2/2/w/600/h/600'
      },
      {
        image: 'https://images.qmai.cn/s23107/2020/05/08/c25de6ef72d2890630.png?imageView2/2/w/600/h/600'
      },
      {
        image: 'https://img-shop.qmimg.cn/s23107/2020/04/10/add546c1b1561f880d.jpg?imageView2/2/w/600/h/600'
      },
      {
        image: 'https://images.qmai.cn/s23107/2020/04/30/b3af19e0de8ed42f61.jpg?imageView2/2/w/600/h/600'
      },
      {
        image: 'https://img-shop.qmimg.cn/s23107/2020/04/17/8aeb78516d63864420.jpg?imageView2/2/w/600/h/600'
      }
    ]
  },
  // tab 切換
  handleTabChange:function(e){
    console.log(e.currentTarget.dataset);
    this.setData({
      selectIndex: e.currentTarget.dataset.index
    })
    this.setData({
      scrollTop:180
    })
  },
  handleScrollToLower:function(){
    // 滾動到最底部
    console.log(this.data.menus.length);
    let selectIndex = (this.data.selectIndex+1)%this.data.menus.length;
    this.setData({
      selectIndex
    })
  },
  // 处理点击外卖跳转逻辑
  handleTakeOut:function(){
    // 跳转到非 tabbar 页面中
    // 判断用户是否有登录
    // 获取本地缓存的token 
    let token = wx.getStorageSync("token");
    // 用户已经登录的情况下
    if(token){
      wx.navigateTo({
        url: '/pages/address/address',
      })
    }else{
      // 没有登录的情况
        wx.navigateTo({
          url: '/pages/login/login',
        })
    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    setTimeout(() => {
      this.setData({
        loading: false
      })
    }, 1500)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  handleDIYClick:function(){
    wx.removeStorageSync('selectedAddress');
    this.setData({
      selectedAddress:{}
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // console.log(123);
    // setTimeout 函数
    // setTimeout(fn,时间)
    // 模拟一下网络请求的时间
    setTimeout(()=>{
      // console.log(456)
      // 修改数据 通过  this.setData 方法进行数据修改，引起界面的更新
      this.setData({
        loading:false
      })
    },1500)
    this.setData({
      selectedAddress:  wx.getStorageSync('selectedAddress')||{}
    })
 
  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})